package com.kintreda.ieco_server.module.order.service.impl;

import com.kintreda.ieco_server.bean.goods.Sack;
import com.kintreda.ieco_server.bean.order.UsageRecord;
import com.kintreda.ieco_server.core.service.impl.BaseServiceImpl;
import com.kintreda.ieco_server.module.order.service.ISackService;
import com.kintreda.ieco_server.module.order.service.IUsageRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Created by IntelliJ IDEA
 * @Project_Name ieco_server
 * @Package com.kintreda.ieco_server.module.order.service.impl
 * @Author ZhongYao_H
 * @Date 2019/4/28:17:11
 * @Year 2019 Month 04 Day 28
 * @Date_zh 2019 年 四月 星期日
 */
@Service
public class SackServiceImpl extends BaseServiceImpl<Sack,String> implements ISackService {

    @Autowired
    IUsageRecordService usageRecordService;

    @Override
    public Boolean isUsable(String code) {
        List<UsageRecord> query = usageRecordService.query("from UsageRecord where qrCode = ? and (status = 0 or status = -2) ", new Object[]{code});
        return query.size()==0;
    }

    @Override
    public Sack getSackByQrCode(String qrcode) {
        List<Sack> query = query("from Sack where qrcode = ? ", new Object[]{qrcode});
        return query.size()>0?query.get(0):null;

    }

    @Override
    public Boolean sackIsUsable(String qrcode) {
        List<Sack> query = query("from Sack where qrcode = ? and status = ? ", new Object[]{qrcode,"0"});
        System.out.println(" query.size = " + query);
        return query.size()>0;
    }
}
